package edu.csl.study.springboot.core.user.controller;


import edu.csl.study.springboot.core.user.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 自动生成代码
 * @since 2021-09-25
 */
@RestController
@RequestMapping("/user/user")
@Api(tags = "用户管理")
public class UserController {
    @Autowired
    edu.csl.study.springboot.core.user.service.IUserService iUserService;
    @ApiOperation("创建用户")
    @PostMapping("/users")
    public User create(@RequestBody @Valid User user) {
        return user;
    }

    @ApiOperation("用户详情")
    @GetMapping("/users/{id}")
    public User findById(@PathVariable Long id) {
        User user= iUserService.getById(id);
        return user;
    }

    @ApiOperation("用户列表")
    @GetMapping("/users")
    public List<User> list(@ApiParam("查看第几页") @RequestParam int pageIndex,
                           @ApiParam("每页多少条") @RequestParam int pageSize) {
        List<User> result = iUserService.list();
        return result;
    }

    @ApiIgnore
    @DeleteMapping("/users/{id}")
    public String deleteById(@PathVariable Long id) {
        return "delete user : " + id;
    }

    @ApiOperation("我的用户")
    @PostMapping("/myuser")
    public User myuser( Long id) {
         iUserService.getMyUser2(1l);
        return iUserService.getMyUser(1l);
    }
}
